﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ISSMoviePlex.BLL;
using ISSMoviePlex.DAL.Models;

namespace ISSMoviePlex.Member.Controllers
{
    public class CommentRateController : Controller
    {
        CommentBLL commentHandle = new CommentBLL();
        MovieBLL movieHandle = new MovieBLL();
        RatingBLL ratingHandle = new RatingBLL();


        //
        // GET: /CommentRate/

        public ActionResult Index()
        {

            return View();
        }
        //[HttpPost]
        //public ActionResult Index()
        //{
        //    Int32 MovId;
        //    Int32 MemId = Int32.Parse(memberid);
        //    Movie m = movieHandle.SearchFirstMovieByTitle(moviename);
        //    MovId = m.MovieId;
        //    Comment c = new Comment();
        //    c.MemberId = MemId;
        //    c.MovieId = MovId;
        //    c.CommentDate = DateTime.Now;
        //    c.CommentContent = comments;
        //    commentHandle.AddComments(c);
        //    return View();
            
        //}

        [HttpPost]
        public ActionResult Index(string moviename, string memberid, string moviecomments, string movierating)
        {
            Int32 MovId;
            Int32 MemId = Int32.Parse(memberid);
            Movie m = movieHandle.SearchFirstMovieByTitle(moviename);
            MovId = m.MovieId;
            Comment c = new Comment();
            c.MemberId = MemId;
            c.MovieId = MovId;
            c.CommentDate = DateTime.Now;
            c.CommentContent = moviecomments;
            commentHandle.AddComments(c);
            if (!string.IsNullOrEmpty(movierating))
            {
                Rating r = new Rating();
                r.MemberId = MemId;
                r.MovieId = MovId;
                r.RatingValue = Int32.Parse(movierating);
                ratingHandle.AddRating(r);
            }
            return View();

        }

    }
}
